﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Reflection;

using GISforTT_API;

namespace eWell_App
{
    /// <summary>
    /// Interaction logic for My_Application.xaml
    /// </summary>
    public partial class My_Application : UserControl
    {
        private Window mainWindow;        
        
        #region Constructor and Initializations
        
        public My_Application(Window startupWindow)
        {
            InitializeComponent();

            LayoutRoot.Height = System.Windows.SystemParameters.VirtualScreenHeight;
            LayoutRoot.Width = System.Windows.SystemParameters.VirtualScreenWidth;

            mainWindow = startupWindow;
            
            this.Loaded += new RoutedEventHandler(My_Application_Loaded);
            this.MouseLeftButtonDown += new MouseButtonEventHandler(My_Application_MouseLeftButtonDown);
        }

        void My_Application_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Point pos = e.GetPosition(this);
            BackgroundMapLayer.Instance.AddMapFrame(new Point(pos.X-50, pos.Y-50), new Point(pos.X+50, pos.Y+50));
        }
                
        private void My_Application_Loaded(object sender, RoutedEventArgs e)
        {
            GisInterfaceMgr bgm = GisInterfaceMgr.Instance;
            bgm.setMainWindow(mainWindow);
            bgm.setCornerMenusType(CornerMenusMgr.CornerMenuType.TwoCornerMenus);
            // Background map is Alberta
            bgm.setBackgroundMapLocation(-119.9, 59.9, -110.1, 49.0);
            //bgm.allowManipulationOfBackgroundMap(true);

            List<MapLayerDef> defaultMapLayers = new List<MapLayerDef>();
            defaultMapLayers.Add(new MapLayerDef(MapLayerDef.MapLayerType.OnlinePublishedMap, 
                "http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"));
            defaultMapLayers.Add(new MapLayerDef(MapLayerDef.MapLayerType.OnlinePublishedMap, 
                "http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer"));
                        
            bgm.setDefaultMapLayerTypes(defaultMapLayers);

            LayoutRoot.Children.Add(bgm);            
        }

        public Window getMainWindow()
        {
            return mainWindow;
        }

        #endregion        
        
    }
}